<?php
echo $header;
echo $column_left;
echo $column_right;
$width_content = '100%';
if (($column_left) && ($column_right)) {
    $width_content = '48%';
} elseif (($column_left) || ($column_right)) {
    $width_content = '74%';
}
$style = '';
if ($column_left) {
    $style .= '; margin-left:1%';
}
if ($column_right) {
    $style .= '; margin-right:1%';
}
?>
<div class="content" style="width:<?php echo $width_content . $style; ?>"><?php echo $content_top; ?>
    <div class="breadcrumb">
        <?php foreach ($breadcrumbs as $breadcrumb) { ?>
            <?php echo $breadcrumb['separator']; ?><a href="<?php echo $breadcrumb['href']; ?>"><?php echo $breadcrumb['text']; ?></a>
        <?php } ?>
    </div>
    <ul data-role="listview" data-divider-theme="a">
        <li data-role="list-divider"><h1><?php echo $heading_title; ?></h1></li>
    </ul>
    <br />
    <div class="product-info">
        <?php if ($thumb || $images) { ?>
            <div id="gallery">
                <?php if ($thumb) { ?>
                    <div class="image"><a href="<?php echo $popup; ?>" title="<?php echo $heading_title; ?>"><img src="<?php echo $thumb; ?>" title="<?php echo $heading_title; ?>" alt="<?php echo $heading_title; ?>" id="image" /></a></div>
                <?php } ?>
                <?php if ($images) { ?>
                    <div class="image-additional">
                        <?php foreach ($images as $image) { ?>
                            <a href="<?php echo $image['popup']; ?>" title="<?php echo $heading_title; ?>"><img src="<?php echo $image['thumb']; ?>" title="<?php echo $heading_title; ?>" alt="<?php echo $heading_title; ?>" /></a>
                        <?php } ?>
                    </div>
                <?php } ?>
            </div>
            <script type="text/javascript">
                $(document).ready(function(){
                    var options = {};
                    $("#gallery a").photoSwipe(options);
                });
            </script>
        <?php } ?>
        <div class="product-detail">
            <div class="description">
                <?php if ($manufacturer) { ?>
                    <span><?php echo $text_manufacturer; ?></span> <a href="<?php echo $manufacturers; ?>"><?php echo $manufacturer; ?></a><br />
                <?php } ?>
                <span><?php echo $text_model; ?></span> <?php echo $model; ?><br />
                <?php if ($reward) { ?>
                    <span><?php echo $text_reward; ?></span> <?php echo $reward; ?><br />
                <?php } ?>
                <span><?php echo $text_stock; ?></span> <?php echo $stock; ?>
            </div>
            <?php if ($price) { ?>
                <div class="price"><?php echo $text_price; ?>
                    <?php if (!$special) { ?>
                        <?php echo $price; ?>
                    <?php } else { ?>
                        <span class="price-old"><?php echo $price; ?></span> <span class="price-new"><?php echo $special; ?></span>
                    <?php } ?>
                    <br />
                    <?php if ($tax) { ?>
                        <span class="price-tax"><?php echo $text_tax; ?> <?php echo $tax; ?></span><br />
                    <?php } ?>
                    <?php if ($points) { ?>
                        <span class="reward"><small><?php echo $text_points; ?> <?php echo $points; ?></small></span> <br />
                    <?php } ?>
                    <?php if ($discounts) { ?>
                        <br />
                        <div class="discount">
                            <?php foreach ($discounts as $discount) { ?>
                                <?php echo sprintf($text_discount, $discount['quantity'], $discount['price']); ?><br />
                            <?php } ?>
                        </div>
                    <?php } ?>
                </div>
            <?php } ?>
            <?php if ($options) { ?>
                <div class="options" data-role="fieldcontain">
                    <h2><?php echo $text_option; ?></h2>
                    <br />
                    <?php foreach ($options as $option) { ?>
                        <?php if ($option['type'] == 'select') { ?>
                            <div id="option-<?php echo $option['product_option_id']; ?>" class="option">
                                <label for="select_option_<?php echo $option['product_option_id']; ?>">
                                    <?php if ($option['required']) { ?>
                                        <span class="required">*</span>
                                    <?php } ?>
                                    <b><?php echo $option['name']; ?>:</b></label>
                                <select data-native-menu="false" id="select_option_<?php echo $option['product_option_id']; ?>" name="option[<?php echo $option['product_option_id']; ?>]">
                                    <option value=""><?php echo $text_select; ?></option>
                                    <?php foreach ($option['option_value'] as $option_value) { ?>
                                        <option value="<?php echo $option_value['product_option_value_id']; ?>"><?php echo $option_value['name']; ?>
                                            <?php if ($option_value['price']) { ?>
                                                (<?php echo $option_value['price_prefix']; ?><?php echo $option_value['price']; ?>)
                                            <?php } ?>
                                        </option>
                                    <?php } ?>
                                </select>
                            </div>
                            <br />
                        <?php } ?>
                        <?php if ($option['type'] == 'radio') { ?>
                            <div id="option-<?php echo $option['product_option_id']; ?>" class="option">
                                <fieldset data-role="controlgroup">
                                    <legend>
                                        <?php if ($option['required']) { ?>
                                            <span class="required">*</span>
                                        <?php } ?>
                                        <b><?php echo $option['name']; ?>:</b>
                                    </legend>
                                    <?php foreach ($option['option_value'] as $option_value) { ?>
                                        <input type="radio" name="option[<?php echo $option['product_option_id']; ?>]" value="<?php echo $option_value['product_option_value_id']; ?>" id="option-value-<?php echo $option_value['product_option_value_id']; ?>" />
                                        <label for="option-value-<?php echo $option_value['product_option_value_id']; ?>"><?php echo $option_value['name']; ?>
                                            <?php if ($option_value['price']) { ?>
                                                (<?php echo $option_value['price_prefix']; ?><?php echo $option_value['price']; ?>)
                                            <?php } ?>
                                        </label>
                                    <?php } ?>
                                </fieldset>
                            </div>
                            <br />
                        <?php } ?>
                        <?php if ($option['type'] == 'checkbox') { ?>
                            <div id="option-<?php echo $option['product_option_id']; ?>" class="option">
                                <fieldset data-role="controlgroup">
                                    <legend>
                                        <?php if ($option['required']) { ?>
                                            <span class="required">*</span>
                                        <?php } ?>
                                        <b><?php echo $option['name']; ?>:</b>
                                    </legend>
                                    <?php foreach ($option['option_value'] as $option_value) { ?>
                                        <input type="checkbox" name="option[<?php echo $option['product_option_id']; ?>][]" value="<?php echo $option_value['product_option_value_id']; ?>" id="option-value-<?php echo $option_value['product_option_value_id']; ?>" />
                                        <label for="option-value-<?php echo $option_value['product_option_value_id']; ?>"><?php echo $option_value['name']; ?>
                                            <?php if ($option_value['price']) { ?>
                                                (<?php echo $option_value['price_prefix']; ?><?php echo $option_value['price']; ?>)
                                            <?php } ?>
                                        </label>
                                    <?php } ?>
                                </fieldset>
                            </div>
                            <br />
                        <?php } ?>
                        <?php if ($option['type'] == 'image') { ?>
                            <div id="option-<?php echo $option['product_option_id']; ?>" class="option">
                                <fieldset data-role="controlgroup">
                                    <legend>
                                        <?php if ($option['required']) { ?>
                                            <span class="required">*</span>
                                        <?php } ?>
                                        <b><?php echo $option['name']; ?>:</b>
                                    </legend>
                                    <div class="option-image">
                                        <?php foreach ($option['option_value'] as $option_value) { ?>
                                            <input type="radio" name="option[<?php echo $option['product_option_id']; ?>]" value="<?php echo $option_value['product_option_value_id']; ?>" id="option-value-<?php echo $option_value['product_option_value_id']; ?>" />
                                            <label for="option-value-<?php echo $option_value['product_option_value_id']; ?>"><img src="<?php echo $option_value['image']; ?>" alt="<?php echo $option_value['name'] . ($option_value['price'] ? ' ' . $option_value['price_prefix'] . $option_value['price'] : ''); ?>" />
                                                <?php echo $option_value['name']; ?>
                                                <?php if ($option_value['price']) { ?>
                                                    (<?php echo $option_value['price_prefix']; ?><?php echo $option_value['price']; ?>)
                                                <?php } ?>
                                            </label>
                                        <?php } ?>
                                    </div>
                                </fieldset>
                            </div>
                            <br />
                        <?php } ?>
                        <?php if ($option['type'] == 'text') { ?>
                            <div id="option-<?php echo $option['product_option_id']; ?>" class="option">
                                <label for="text_option_<?php echo $option['product_option_id']; ?>">
                                    <?php if ($option['required']) { ?>
                                        <span class="required">*</span>
                                    <?php } ?>
                                    <b><?php echo $option['name']; ?>:</b>
                                </label>
                                <input type="text" id="text_option_<?php echo $option['product_option_id']; ?>" name="option[<?php echo $option['product_option_id']; ?>]" value="<?php echo $option['option_value']; ?>" />
                            </div>
                            <br />
                        <?php } ?>
                        <?php if ($option['type'] == 'textarea') { ?>
                            <div id="option-<?php echo $option['product_option_id']; ?>" class="option">
                                <label for="textarea_option_<?php echo $option['product_option_id']; ?>">
                                    <?php if ($option['required']) { ?>
                                        <span class="required">*</span>
                                    <?php } ?>
                                    <b><?php echo $option['name']; ?>:</b>
                                </label>
                                <textarea id="textarea_option_<?php echo $option['product_option_id']; ?>" name="option[<?php echo $option['product_option_id']; ?>]" cols="40" rows="5"><?php echo $option['option_value']; ?></textarea>
                            </div>
                            <br />
                        <?php } ?>
                        <?php if ($option['type'] == 'file') { ?>
                            <div id="option-<?php echo $option['product_option_id']; ?>" class="option">
                                <label for="button-option-<?php echo $option['product_option_id']; ?>">
                                    <?php if ($option['required']) { ?>
                                        <span class="required">*</span>
                                    <?php } ?>
                                    <b><?php echo $option['name']; ?>:</b>
                                </label>
                                <a data-inline="true" id="button-option-<?php echo $option['product_option_id']; ?>" data-icon="arrow-u" data-role="button"><?php echo $button_upload; ?></a>
                                <input type="hidden" name="option[<?php echo $option['product_option_id']; ?>]" value="" />
                            </div>
                            <br />
                        <?php } ?>
                        <?php if ($option['type'] == 'date') { ?>
                            <div id="option-<?php echo $option['product_option_id']; ?>" class="option">
                                <label for="date_option_<?php echo $option['product_option_id']; ?>">
                                    <?php if ($option['required']) { ?>
                                        <span class="required">*</span>
                                    <?php } ?>
                                    <b><?php echo $option['name']; ?>:</b>
                                </label>
                                <input type="text" id="date_option_<?php echo $option['product_option_id']; ?>" name="option[<?php echo $option['product_option_id']; ?>]" value="<?php echo $option['option_value']; ?>" class="date" />
                            </div>
                            <br />
                        <?php } ?>
                        <?php if ($option['type'] == 'datetime') { ?>
                            <div id="option-<?php echo $option['product_option_id']; ?>" class="option">
                                <label for="datetime_option_<?php echo $option['product_option_id']; ?>">
                                    <?php if ($option['required']) { ?>
                                        <span class="required">*</span>
                                    <?php } ?>
                                    <b><?php echo $option['name']; ?>:</b>
                                </label>
                                <input type="text" id="datetime_option_<?php echo $option['product_option_id']; ?>" name="option[<?php echo $option['product_option_id']; ?>]" value="<?php echo $option['option_value']; ?>" class="datetime" />
                            </div>
                            <br />
                        <?php } ?>
                        <?php if ($option['type'] == 'time') { ?>
                            <div id="option-<?php echo $option['product_option_id']; ?>" class="option">
                                <label for="time_option_<?php echo $option['product_option_id']; ?>">
                                    <?php if ($option['required']) { ?>
                                        <span class="required">*</span>
                                    <?php } ?>
                                    <b><?php echo $option['name']; ?>:</b>
                                </label>
                                <input type="text" id="time_option_<?php echo $option['product_option_id']; ?>" name="option[<?php echo $option['product_option_id']; ?>]" value="<?php echo $option['option_value']; ?>" class="time" />
                            </div>
                        <?php } ?>
                    <?php } ?>
                </div>
            <?php } ?>
            <div class="cart">
                <div data-role="fieldcontain">
                    <input type="hidden" name="product_id" size="2" value="<?php echo $product_id; ?>" />
                    <input type="hidden" name="quantity" id="quantity" size="2" value="<?php echo $minimum; ?>" />
                    <label for="slider"><?php echo $text_qty; ?></label>
                    <input onchange="document.getElementById('quantity').value = this.value;" type="range" name="slider" id="slider" value="<?php echo $minimum; ?>" min="<?php echo $minimum; ?>" max="100"  />
                    &nbsp;<a data-inline="true" id="button-cart" data-role="button" data-icon="myapp-cart" data-theme="c"><?php echo $button_cart; ?></a>
                </div>
                <div data-role="controlgroup" data-type="horizontal">
                    <a data-icon="plus" data-role="button" onclick="addToWishList('<?php echo $product_id; ?>');"><?php echo $button_wishlist; ?></a>
                    <a data-icon="plus" data-role="button" onclick="addToCompare('<?php echo $product_id; ?>');"><?php echo $button_compare; ?></a>
                </div>
                <?php if ($minimum > 1) { ?>
                    <div class="minimum"><?php echo $text_minimum; ?></div>
                <?php } ?>
            </div>
            <?php if ($review_status) { ?>
                <div class="review">
                    <div><img src="catalog/view/theme/mobile/image/stars-<?php echo $rating; ?>.png" alt="<?php echo $reviews; ?>" />&nbsp;&nbsp;<a onclick="$('a[href=\'#tab-review\']').trigger('click');"><?php echo $reviews; ?></a>&nbsp;&nbsp;|&nbsp;&nbsp;<a onclick="$('a[href=\'#tab-review\']').trigger('click');"><?php echo $text_write; ?></a></div>
                    <div class="share"><!-- AddThis Button BEGIN -->
                        <div class="addthis_default_style"><a class="addthis_button_compact"><?php echo $text_share; ?></a> <a class="addthis_button_email"></a><a class="addthis_button_print"></a> <a class="addthis_button_facebook"></a> <a class="addthis_button_twitter"></a></div>
                        <script type="text/javascript" src="http://s7.addthis.com/js/250/addthis_widget.js"></script>
                        <!-- AddThis Button END -->
                    </div>
                </div>
            <?php } ?>
        </div>
    </div>
    <div class="Clear"><br /></div>

    <div data-role="collapsible-set" data-theme="a" data-content-theme="a">

        <div data-role="collapsible">
            <h3><?php echo $tab_description; ?></h3>
            <p><?php echo $description; ?></p>
        </div>

        <?php if ($attribute_groups) { ?>
            <div data-role="collapsible">
                <h3><?php echo $tab_attribute; ?></h3>
                <div>
                    <ul data-role="listview" data-divider-theme="a" data-inset="true" class="attribute" data-theme="a" data-content-theme="a">
                        <?php foreach ($attribute_groups as $attribute_group) { ?>
                            <li data-role="list-divider"><?php echo $attribute_group['name']; ?></li>
                            <?php foreach ($attribute_group['attribute'] as $attribute) { ?>
                                <li><?php echo $attribute['name']; ?>: <?php echo $attribute['text']; ?></li>
                            <?php } ?>
                        <?php } ?>
                    </ul>
                </div>
            </div>
        <?php } ?>

        <?php if ($review_status) { ?>
            <div data-role="collapsible">
                <h3><?php echo $tab_review; ?></h3>
                <div>
                    <ul data-role="listview" data-divider-theme="a" data-inset="true" data-theme="a" data-content-theme="a">
                        <li><div id="review"></div><br /></li>
                    </ul><br />
                    <h2><?php echo $text_write; ?></h2>
                    <div data-role="fieldcontain">
                        <label for="name_review"><b><?php echo $entry_name; ?></b></label>
                        <input type="text" id="name_review" name="name" value="" />
                        <br />
                        <br />
                        <label for="text_review"><b><?php echo $entry_review; ?></b></label>
                        <textarea name="text" id="text_review" cols="40" rows="8"></textarea><br />
                        <span style="font-size: 11px;"><?php echo $text_note; ?></span><br />
                        <br />
                        <fieldset data-role="controlgroup">
                            <legend><b><?php echo $entry_rating; ?></b></legend><span><?php echo $entry_bad; ?></span>&nbsp;
                            <input type="radio" name="rating" value="1" id="radio-1" /><label for="radio-1">1</label>
                            <input type="radio" name="rating" value="2" id="radio-2" /><label for="radio-2">2</label>
                            <input type="radio" name="rating" value="3" id="radio-3" /><label for="radio-3">3</label>
                            <input type="radio" name="rating" value="4" id="radio-4" /><label for="radio-4">4</label>
                            <input type="radio" name="rating" value="5" id="radio-5" /><label for="radio-5">5</label>
                            &nbsp; <span><?php echo $entry_good; ?></span>
                        </fieldset><br />
                        <br />
                        <label for="captcha"><b><?php echo $entry_captcha; ?></b></label>
                        <input type="text" name="captcha" value="" />
                        <br />
                        <img src="index.php?route=product/product/captcha" alt="" id="captcha" /><br />
                        <br />
                        <a id="button-review" data-role="button"><?php echo $button_continue; ?></a>
                    </div>
                </div>
            </div>
        <?php } ?>

        <?php if ($products) { ?>
            <div data-role="collapsible">
                <h3><?php echo $tab_related; ?> (<?php echo count($products); ?>)</h3>
                <div>
                    <ul data-role="listview" data-divider-theme="a">
                        <?php foreach ($products as $product) { ?>
                            <li><a href="<?php echo $product['href']; ?>">
                                    <?php if ($product['thumb']) { ?>
                                        <img src="<?php echo $product['thumb']; ?>" alt="<?php echo $product['name']; ?>" />
                                    <?php } ?>
                                    <h3><?php echo $product['name']; ?></h3>
                                    <div>
                                        <?php if ($product['price']) { ?>
                                            <div class="price">
                                                <?php if (!$product['special']) { ?>
                                                    <?php echo $product['price']; ?>
                                                <?php } else { ?>
                                                    <span class="price-old"><?php echo $product['price']; ?></span> <span class="price-new"><?php echo $product['special']; ?></span>
                                                <?php } ?>
                                            </div>
                                        <?php } ?>
                                        <?php if ($product['rating']) { ?>
                                            <div class="rating"><img src="catalog/view/theme/mobile/image/stars-<?php echo $product['rating']; ?>.png" alt="<?php echo $product['reviews']; ?>" /></div>
                                        <?php } ?>
                                    </div>
                                </a></li>
                        <?php } ?>
                    </ul>
                </div>
            </div>
        <?php } ?>
    </div>

    <?php if ($tags) { ?>
        <div data-role="controlgroup" data-type="horizontal" class="tags"><b><?php echo $text_tags; ?></b>
            <?php foreach ($tags as $tag) { ?>
                <a data-role="button" data-mini="true" data-theme="a" href="<?php echo $tag['href']; ?>"><?php echo $tag['tag']; ?></a>
            <?php } ?>
        </div>
    <?php } ?>
    <?php echo $content_bottom; ?></div>
<script type="text/javascript"><!--
    $('#button-cart').bind('click', function() {
        $.ajax({
            url: 'index.php?route=checkout/cart/add',
            type: 'post',
            data: $('.product-info input[type=\'text\'], .product-info input[type=\'hidden\'], .product-info input[type=\'radio\']:checked, .product-info input[type=\'checkbox\']:checked, .product-info select, .product-info textarea'),
            dataType: 'json',
            success: function(json) {
                $('.success, .warning, .attention, information, .error').remove();

                if (json['error']) {
                    if (json['error']['option']) {
                        for (i in json['error']['option']) {
                            $('#option-' + i).after('<div class="error">' + json['error']['option'][i] + '</div>');
                        }
                    }
                }

                if (json['success']) {
                    $('#notification').html('<div class="success" style="display: none;">' + json['success'] + ' <img src="catalog/view/theme/mobile/image/close.png" alt="" class="close" /></div>');

                    $('.success').fadeIn('slow');

                    $('#cart-total').html(json['total']);

                    $('html, body').animate({ scrollTop: 0 }, 'slow');
                }
            }
        });
    });
    //--></script>
<?php if ($options) { ?>
    <script type="text/javascript" src="catalog/view/javascript/jquery/ajaxupload.js"></script>
    <?php foreach ($options as $option) { ?>
        <?php if ($option['type'] == 'file') { ?>
            <script type="text/javascript"><!--
                new AjaxUpload('#button-option-<?php echo $option['product_option_id']; ?>', {
                    action: 'index.php?route=product/product/upload',
                    name: 'file',
                    autoSubmit: true,
                    responseType: 'json',
                    onSubmit: function(file, extension) {
                        $('#button-option-<?php echo $option['product_option_id']; ?>').after('<img src="catalog/view/theme/mobile/image/loading.png" class="loading" style="padding-left: 5px;" />');
                    },
                    onComplete: function(file, json) {
                        $('.error').remove();

                        if (json.success) {
                            alert(json.success);

                            $('input[name=\'option[<?php echo $option['product_option_id']; ?>]\']').attr('value', json.file);
                        }

                        if (json.error) {
                            $('#option-<?php echo $option['product_option_id']; ?>').after('<span class="error">' + json.error + '</span>');
                        }

                        $('.loading').remove();
                    }
                });
                //--></script>
        <?php } ?>
    <?php } ?>
<?php } ?>
<script type="text/javascript"><!--
    $('#review .pagination a').live('click', function() {
        $('#review').slideUp('slow');

        $('#review').load(this.href);

        $('#review').slideDown('slow');

        return false;
    });

    $('#review').load('index.php?route=product/product/review&product_id=<?php echo $product_id; ?>');

    $('#button-review').bind('click', function() {
        $.ajax({
            type: 'POST',
            url: 'index.php?route=product/product/write&product_id=<?php echo $product_id; ?>',
            dataType: 'json',
            data: 'name=' + encodeURIComponent($('input[name=\'name\']').val()) + '&text=' + encodeURIComponent($('textarea[name=\'text\']').val()) + '&rating=' + encodeURIComponent($('input[name=\'rating\']:checked').val() ? $('input[name=\'rating\']:checked').val() : '') + '&captcha=' + encodeURIComponent($('input[name=\'captcha\']').val()),
            beforeSend: function() {
                $('.success, .warning').remove();
                $('#button-review').attr('disabled', true);
                $('#review-title').after('<div class="attention"><img src="catalog/view/theme/mobile/image/loading.png" alt="" /> <?php echo $text_wait; ?></div>');
            },
            complete: function() {
                $('#button-review').attr('disabled', false);
                $('.attention').remove();
            },
            success: function(data) {
                if (data.error) {
                    $('#review-title').after('<div class="warning">' + data.error + '</div>');
                }

                if (data.success) {
                    $('#review-title').after('<div class="success">' + data.success + '</div>');

                    $('input[name=\'name\']').val('');
                    $('textarea[name=\'text\']').val('');
                    $('input[name=\'rating\']:checked').attr('checked', '');
                    $('input[name=\'captcha\']').val('');
                }
            }
        });
    });
    //--></script>
<?php echo $footer; ?>